<?php
$childmod = get_get("childmod");
$op = get_get("op");
if (! isAjaxRequest()) {} else {
    if (get_get("uid") && getSessionUid() != get_get("uid")) {
        printMessage("error", "你的请求无效，无权访问他人家园的提醒，如果您是管理员，需要查询他的提醒，请进入管理面板。");
        die();
    }
    if ($op == "notices") {
        loadTemp("home/notice_view/notices.php");
        die();
    }
    if ($op == "sendleavemessage") {
        $data = array();
        $reply = get_get("lreply");
        if ($reply) {
            $ldata = getLeaveMessage($reply);
            if (! $ldata) {
                printMessage("error", "你要回复的目标留言不存在");
                die();
            }
            if (getSessionUid() != $ldata["target"]) {
                printMessage("error", "你为什么要给别人的留言进行回复呢");
                die();
            }
            $uid = $ldata["uid"];
            $data["isReply"] = true;
            $data["reply"] = base64_encode(getQuote($ldata, true));
            $data["replyid"] = $ldata["lid"];
        } else {
            $data["isReply"] = false;
            $uid = get_get("luid");
        }
        if ($uid) {
            if ($uid == getSessionUid()) {
                printMessage("error", "你不能给自己留言的");
                die();
            }
            $card = getCardInfo($uid);
            if (! $card) {
                printMessage("error", "你所选择的用户不存在或无法找到");
                die();
            }
            if (! allowLeaveMessage(getSessionUid(), $uid)) {
                printMessage("error", "对方家园禁止留言或对方禁止你留言");
                die();
            }

            $data["card"] = $card;
            $data["isSelected"] = true;
            $data["uid"] = $uid;
        } else {
            $data["isSelected"] = false;
        }
        setSetting("send_leave_message", $data);
        loadTemp("home/notice_view/sendleavemessage.php");
        die();
    }
    if ($op == "receive_q") {
        $data = array();
        $data["receivemode"] = true;
        $data["uid"] = getSessionUid();
        $data["reqid"] = get_get("luid") == "" ? - 1 : get_get("luid");
        setSetting("list_leave_message", $data);
        loadTemp("home/notice_view/leavemessage.php");
        die();
    }
    if ($op == "sent_q") {
        $data = array();
        $data["receivemode"] = false;
        $data["uid"] = getSessionUid();
        $data["reqid"] = get_get("luid") == "" ? - 1 : get_get("luid");
        setSetting("list_leave_message", $data);
        loadTemp("home/notice_view/leavemessage.php");
        die();
    }
    if ($op == "receive") {
        $uid = getSessionUid();
        $sender = get_post("sender");
        $offset = get_post("offset");
        if (! $offset) {
            $offset = 0;
        }
        $back = array();
        $data = null;
        if ($sender == - 1) {
            global $_G;
            if ($_G["notreadlmamount"] <= 10) {
                $data = listLeaveMessageByTargetID($uid, $offset, 10);
            } else {
                $data = getNotReadLM($uid);
            }
            read_all_lm($uid);
            $back["only_see_him_mode"] = false;
        } else {
            $back["only_see_him_mode"] = true;
            $data = listLeaveMessageByUIDToTargetID($sender, $uid, $offset, 10);
        }
        $back["bottom"] = false;
        $amount = count($data);
        $back["amount"] = $amount;
        $back["data"] = $data;
        $back["op"] = "load_more";
        if ($amount < 10) {
            $back["bottom"] = true;
        }
        returnMessage(0, "receive 操作成功 $sender $uid", $back);
    }
    if ($op == "sent") {
        $uid = getSessionUid();
        $target = get_post("target");
        $offset = get_post("offset");
        if (! $offset) {
            $offset = 0;
        }
        $back = array();
        $data = null;
        if ($target == - 1) {
            $back["only_see_him_mode"] = false;
            $data = listLeaveMessageByUID($uid, $offset, 10);
        } else {
            $back["only_see_him_mode"] = true;
            $data = listLeaveMessageByUIDToTargetID($uid, $target, $offset, 10);
        }
        $back["bottom"] = false;
        $amount = count($data);
        $back["amount"] = $amount;
        $back["data"] = $data;
        $back["op"] = "load_more";
        $back["target"] = $target;
        if ($amount < 10) {
            $back["bottom"] = true;
        }
        returnMessage(0, "sent操作成功 $target,$uid", $back);
    }
    if ($op == "leavemessage_search") {
        $account = get_post("account");
        if (! $account) {
            returnMessage(- 2, "你没输入账户啊");
        }
        $uid = getUID($account);
        if ($uid == - 1) {
            returnMessage(- 1, "您要找的账户不存在呢");
        }
        $data = array();
        if ($uid == getSessionUid()) {
            returnMessage(- 4, "你不能给自己留言的");
        }
        $card = getCardInfo($uid);
        if (! $card) {
            returnMessage(- 3, "你所选择的用户不存在或无法找到");
        }
        if (! allowLeaveMessage(getSessionUid(), $uid)) {
            returnMessage(- 5, "对方家园禁止留言或对方禁止你留言");
        }
        $data["card"] = $card;
        $data["uid"] = $uid;
        $data["op"] = "search";
        $data["isReply"] = false;
        returnMessage(0, "搜索成功", $data);
    }
    if ($op == "leavemessage_send") {
        $uid = get_post("uid");
        $data = array();
        $data["op"] = "send";
        $reply = get_post("reply");
        $content = get_post("content");
        if (! $content) {
            returnMessage(- 7, "回复内容不能为空");
        }
        $uid = null;
        if ($reply != - 1) {
            $ldata = getLeaveMessage($reply);
            if (! $ldata) {
                returnMessage(- 1, "你要回复的目标留言不存在");
            }
            if (getSessionUid() != $ldata["target"]) {
                returnMessage(- 2, "你为什么要给别人的留言进行回复呢");
            }
            $uid = $ldata["uid"];
        } else {
            $uid = get_post("uid");
        }
        if (! $uid) {
            returnMessage(- 4, "你没有明确留言目标");
        }
        if ($uid == getSessionUid()) {
            returnMessage(- 4, "你不能给自己留言的");
        }
        if (! allowLeaveMessage(getSessionUid(), $uid)) {
            returnMessage(- 5, "对方家园禁止留言或对方禁止你留言");
        }
        sendLeaveMessage(getSessionUid(), $content, $uid, $reply);
        returnMessage(0, "Ces$reply", $data);
    }
    if ($op == "notice_load_more") {
        $uid = getSessionUid();
        $offset = get_post("offset");
        if (! $offset) {
            $offset = 0;
        }
        $back = array();
        global $_G;
        if ($_G["noticeamount"] <= 10) {
            $data = getNoticesLimited($uid, $offset);
        } else {
            $data = getNotReadNotices($uid);
        }
        read_all_Notice($uid);
        $back["bottom"] = false;
        $amount = count($data);
        $back["amount"] = $amount;
        $back["data"] = $data;
        $back["op"] = "load_more";
        if ($amount < 10) {
            $back["bottom"] = true;
        }
        returnMessage(0, "操作成功", $back);
    }
}
returnMessage("-2", "unknownrequest: $op");
?>